package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.service.ItemCatService;
import com.dongdongshop.vo.CatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("cat")
public class CatController {

    @Autowired
    private ItemCatService itemCatService;

    //查询
    @PostMapping
    public Result CatList(@RequestParam Long parentId){
        List<CatVo> voList = itemCatService.CatList(parentId);
        return Result.OK().setData(voList);
    }

    @PostMapping("addcat")
    public Result addcat(@RequestBody CatVo catVo){
        itemCatService.addCat(catVo);
        return Result.OK();
    }

    //回显
    @PostMapping(value = "toupdate")
    public Result toupdate(@RequestParam Long id){
        CatVo vo = itemCatService.toupdate(id);
        return Result.OK().setData(vo);
    }

    //修改
    @PutMapping
    public Result update(@RequestBody CatVo vo ){
        itemCatService.update(vo);
        return Result.OK();
    }

    //删除
    @DeleteMapping
    public Result delcat(@RequestParam Long id) {
        itemCatService.delcat(id);
        return Result.OK();
    }

}
